package com.kaifamiao.www.demo.do0809.ex;

public class Demo04 {
    public static void main(String[] args) throws ClassNotFoundException {
        /*
        抛异常 throw  throws
        throw 表示人为抛出一个异常对象
        throws 表示声明方法可能会产生一个异常
     */
        try {
            setAge(1000);
        }catch (AgeException e){
            e.printStackTrace();
        }
        setGender("11");
    }
    public static void setGender(String gender){
        if ("男".equals(gender) || "女".equals(gender) ){

        }else{
            throw new GenderException();
        }
    }
    public static void setAge(int age)throws AgeException {
        if(age < 0 || age >120){
            throw new AgeException("年龄不对，age="+age);
        }
    }
}
